package com.example.vae.Home.Information;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.vae.Adapter.InforRecyclerViewAdapter;
import com.example.vae.InformationViewModel;
import com.example.vae.R;
import com.example.vae.databinding.InformationFragmentBinding;

import java.util.ArrayList;
import java.util.List;

//    这个是第四个页面 ，放一些 官方消息，比如官方页面，我的，评论
public class InformationFragment extends Fragment {

    private InformationViewModel mViewModel;
    private InformationFragmentBinding binding;


    private InforRecyclerViewAdapter myRecyclerViewAdapter;
    private RecyclerView recyclerView;
    private List<Integer> imageviews=new ArrayList<>();
    private List<String> strings=new ArrayList<>();

    public static InformationFragment newInstance() {
        return new InformationFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        mViewModel = ViewModelProviders.of(requireActivity()).get(InformationViewModel.class);
        binding = DataBindingUtil.inflate(inflater, R.layout.information_fragment, container, false);
        binding.setData(mViewModel);
//        设置数据变化 的观察
        binding.setLifecycleOwner(requireActivity());
//       初始化 information 页面的数据
        inititem();

//        加载 information 页面的 recycleview 数据
        myRecyclerViewAdapter=new InforRecyclerViewAdapter(getContext(),imageviews,strings);
        recyclerView=binding.re;
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(myRecyclerViewAdapter);



        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        // TODO: Use the ViewModel
    }

//    加载数据
    public void inititem(){
        imageviews.add(R.drawable.ic_in_1);
        imageviews.add(R.drawable.ic_in_2);
        imageviews.add(R.drawable.ic_in_3);
        imageviews.add(R.drawable.ic_in_4);
        imageviews.add(R.drawable.ic_in_5);
        imageviews.add(R.drawable.ic_in_6);


        strings.add("官方消息");
        strings.add("@我的");
        strings.add("评论");
        strings.add("赞");
        strings.add("喂");
        strings.add("陌生人");


    }

}
